package com.gxitsky.job;

import com.gxitsky.common.listener.RequestListener;
import com.gxitsky.service.DoubleColorBallService;
import com.gxitsky.service.WebSiteService;
import com.gxitsky.utils.UidUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.ThreadContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author gxing
 * @desc 同步数据Job
 * @date 2022/12/5
 */
@Slf4j
@Component
public class SyncDataJob {

    @Autowired
    private DoubleColorBallService doubleColorBallService;
    @Autowired
    private WebSiteService webSiteService;

    @Scheduled(cron = "@daily")
    public void syncDoubleColorBallLastData() {
        //给请求增加全局唯一ID给日志输出用
        ThreadContext.put(RequestListener.LOG_ID, UidUtil.getUID().toString());
        log.info("----->syncDoubleColorBallLastData Job start");
        doubleColorBallService.syncLast();
        log.info("----->syncDoubleColorBallLastData Job end");
    }

    @Scheduled(cron = "@daily")
    public void pushWebSiteResource() {
        ThreadContext.put(RequestListener.LOG_ID, UidUtil.getUID().toString());
        log.info("----->pushWebSiteResource Job start");
        webSiteService.pushWebSiteResource();
        log.info("----->pushWebSiteResource Job end");
    }
}
